package com.spade.dsms.response;

/**
 * @author Weikang  Wang
 * @program: com.spade.dsms.response
 * @description: 返回信息类
 * @date 2019/11/5 14:52
 */
public class CommonReturnType {

    /**
     * 表明对应请求的返回处理结果“success”或者“fail”
     */
    private String status;
    /**
     * 若success，则data内返回前端需要的json数据
     * 若fail，则data内返回通用的错误码格式
     */
    private Object data;

    /**
     * 定义一个通用的创建方法
     *
     * @param result 结果
     * @return
     */
    public static CommonReturnType create(Object result) {
        return CommonReturnType.create(result, "success");
    }

    public static CommonReturnType create(Object result, String status) {
        CommonReturnType type = new CommonReturnType();
        type.setStatus(status);
        type.setData(result);
        return type;
    }


    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "CommonReturnType{" +
                "status='" + status + '\'' +
                ", data=" + data +
                '}';
    }
}
